
#include "ptdebug.h"

#if defined(_WIN32) || defined(linux)
#include "stdio.h"
#endif  //_WIN32 || linux

#ifdef PT_DEBUG
/**
 * The PT_ASSERT function.
 *
 * @param ex the assertion condition string
 * @param func the function name when assertion.
 * @param line the file line number when assertion.
 */
void pt_assert_handler(const char *ex_string, const char *func, uint32_t line)
{
    volatile char dummy = 0;

    printk(KERN_EMERG "(%s) assertion failed at function:%s, line number:%d \n", ex_string, func, line);

    while (dummy == 0);

}

static int console_printk[4] = {
	DEFAULT_CONSOLE_LOGLEVEL,   /*控制台日志级别，优先级高于该值的消息将在控制台显示*/

	DEFAULT_MESSAGE_LOGLEVEL,   /*默认消息日志级别，printk没定义优先级时，打印这个优先级以上的消息*/

	MINIMUM_CONSOLE_LOGLEVEL,   /*最小控制台日志级别，控制台日志级别可被设置的最小值（最高优先级）*/

	DEFAULT_CONSOLE_LOGLEVEL,   /* 默认的控制台日志级别*/
};

#include <stdarg.h>
int printk(const char *fmt, ...)
{
	va_list args;

	va_start(args, fmt);


    if (fmt[0] == '<' && fmt[2] == '>' && fmt[1] >= '0' && fmt[1] <= '7' ){
        if ( fmt[1] - 0x30 <= console_printk[0]){
            platform_log(fmt, args);
        }

    }else{  // 未提供等级
        char *default_lvl = KERN_DEFAULT;
        if ( default_lvl[1] - 0x30 <= console_printk[1]){
            platform_log(fmt, args);
        }
    }

	va_end(args);

	return 0;
}

#endif /* PT_DEBUG */
